package com.molichuxing.gateway.bff.car.services.Impl;

import com.molichuxing.gateway.bff.car.convertor.Convert;
import com.molichuxing.gateway.bff.car.entity.response.CarInsuranceVo;
import com.molichuxing.gateway.bff.car.services.InsuranceBffService;
import com.molichuxing.services.business.dto.response.CarInsuranceDto;
import com.molichuxing.services.business.service.CarInsuranceBizService;
import com.molichuxing.services.business.service.VehicleBizService;
import com.molichuxing.services.infrastructure.dto.response.InsuranceCompanyDto;
import com.molichuxing.services.infrastructure.service.InsuranceCompanyService;
import com.molichuxing.services.property.CarInsuranceTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 车辆检验bff
 * @author xuelin yi
 */
@Service("insuranceBffService")
public class InsuranceBffServiceImpl implements InsuranceBffService {

	private static final Logger logger = LoggerFactory.getLogger(InsuranceBffServiceImpl.class);

	@Resource
	private CarInsuranceBizService carInsuranceBizService;

	@Resource
	private VehicleBizService vehicleBizService;


	@Resource
	private InsuranceCompanyService insuranceCompanyService;

	@Override
	public List<CarInsuranceVo> getInsuranceList(Integer carId, Integer type) {
		List<CarInsuranceDto> list = carInsuranceBizService.getInsuranceList(carId, CarInsuranceTypeEnum.getEnum(type));
		List<CarInsuranceVo> result = Convert.toCarInsuranceVoPage(list);
		if((null != result)&&(result.size() > 0)) {
			for(CarInsuranceVo carInsuranceVo : result) {
				InsuranceCompanyDto insureCompany = insuranceCompanyService.getInsuranceCompanyName(carInsuranceVo.getInsuranceCompanyId());
				if(null != insureCompany) {
					carInsuranceVo.setInsuranceCompanyName(insureCompany.getName());
				}
			}
		}
		return result;
	}

}
